//
//  CustomTileOverlay.m
//  amap_flutter_map
//
//  Created by 张利彬 on 2025/4/25.
//

#import "CustomTileOverlay.h"

NS_ASSUME_NONNULL_BEGIN

@implementation CustomTileOverlay

- (NSURL *)URLForTilePath:(MATileOverlayPath)path {
    if (!self.tileURLTemplate) {
            return nil; // 防御性处理
        }
    
    // 在URLForTilePath方法中添加：
    NSString *urlStr = [[[self.tileURLTemplate
                         stringByReplacingOccurrencesOfString:@"{z}" withString:@(path.z).stringValue]
                         stringByReplacingOccurrencesOfString:@"{x}" withString:@(path.x).stringValue]
                         stringByReplacingOccurrencesOfString:@"{y}" withString:@(path.y).stringValue];
       // 自动识别本地或远程路径
       if ([urlStr hasPrefix:@"http://"] || [urlStr hasPrefix:@"https://"]) {
           return [NSURL URLWithString:urlStr];
       } else {
           return [NSURL fileURLWithPath:urlStr];
       }
}

@end

NS_ASSUME_NONNULL_END
